<!DOCTYPE html>
<html lang="en" style="background-color: #fff;">

<head>
	<meta charset="UTF-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>地址</title>

	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/yzl.css" />

</head>

<body style="background-color: #fff;">
	<div id="blank" class="header">
		<div v-back.tapmode class="back"></div>
		<span class="title">充值地址</span>
		<span v-open-win.tapmode vurl="recharge_list" style="position:absolute;right:10px;font-size:14px;">充值明细</span>
	</div>
	<div id="app" class="main-container">
		<div style="margin:20px">充值地址</div>
		<div style="text-align: center;margin-top:10px"><img :src="qrcode" ></div>
		<div v-myclick="[address, saveqrcode]" style="font-size:14px;padding:4px 6px;border-radius: 4px;border: 1px solid #FD6130;width: 100px;margin:0 auto;margin-top:5px;text-align: center;">保存二维码</div>
        <div style="font-size: 13px;color:#666;text-align: center;margin-top: 26px;">充币地址</div>
		<div style="margin:0 auto;margin-top:10px;text-align: left;width: 90%;word-wrap: break-word;">{{address}}</div>
        <div v-myclick="[address, copyaddress]" style="font-size:14px;padding:4px 6px;border-radius: 4px;border: 1px solid #FD6130;width: 100px;margin:0 auto;margin-top:20px;text-align: center;">复制地址</div>
		<div style="margin:12px;">充值须知</div>
		<div style="font-size: 13px;padding:8px 15px">
			<p>* CC 充值经过 3 个确认后到账，3 个确认后才允许提现</p>
			<p>* 最小充值金额 0 CC，小于该值将不会到账</p>
			<p>* 请不要向这个地址充值除CC之外的资产，任何充入此地址的其他资产将不可找回</p>
		</div>
	</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>
	var user,clipBoard,scanner,qrcode;
	apiready = function () {
        clipBoard = api.require('clipBoard');
        scanner = api.require('FNScanner');
		setBSImg();
		new Vue({
			el: '#blank'
		});
		user = JSON.parse(getPrefs('user'));
		encodeImg(api.pageParam.address);
		api.parseTapmode();
		addListeners();
	};

	function initApp(qrcode) {
		var vm = new Vue({
			el: '#app',
			data: {
				address: api.pageParam.address,
				qrcode:qrcode,
				BSImg: {
					big: Vue.BSImg == 'big',
					small: Vue.BSImg == 'small'
				}
			},
			watch: {
				nickname: function (n, o) {
					this.nameByte = n.replace(/[^\x00-\xff]/g, "xx").length;
					if (this.nameByte > 24) {
						this.nickname = o;
					}
				}
			},
			methods: {
                copyaddress: function (text) {
                    clipBoard.set({
                        value: text
                    }, function (ret) {
                        if (ret) {
                            api.toast({
                                msg: '已复制到剪贴板',
                            });
                        }
                    });
                },
				saveqrcode(address){
				saveencodeImg(address)
			}
			},
			mounted: function () {
				var input = document.getElementById('input');
			},
		});
	}
	function saveencodeImg(qrcode) {
        scanner.encodeImg({
            content: qrcode,
			saveToAlbum: true,
            saveImg: {
                path: 'fs://addressqrcode.png',
                w:200,
                h:200
            }
        }, function (ret) {
			api.toast({
                            msg: '保存成功'
                        });

        })
    }
    function encodeImg(qrcode) {
        scanner.encodeImg({
            content: qrcode,
            saveImg: {
                path: 'fs://addressqrcode.png',
                w:200,
                h:200
            }
        }, function (ret) {
            qrcode = {};
            if(ret.status){
               qrcode = ret.imgPath;
            }
			console.log(qrcode)
			initApp(qrcode);

        })
    }
	function addListeners() {
		api.addEventListener({
			name: 'viewappear'
		}, function () {
			onPageStart();
		});

		api.addEventListener({
			name: 'viewdisappear'
		}, function (ret, err) {
			onPageEnd();
		});

		api.addEventListener({
			name: 'keyback'
		}, function (ret, err) {
			onPageEnd();
			api.closeWin();
		});
	}
</script>

</html>